//
//  ApplyRecommendViewController.m
//  WorkNest
//
//  Created by qbm360 on 15/7/23.
//  Copyright (c) 2015年 nest. All rights reserved.
//

#import "ApplyRecommendViewController.h"

@interface ApplyRecommendViewController () <UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UITextField *priceProportion;
@property (weak, nonatomic) IBOutlet UITextView *message;
@property (weak, nonatomic) IBOutlet UILabel *label;

@end

@implementation ApplyRecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"上架";
    _message.delegate = self;
    _message.layer.borderWidth = 1;
    _message.layer.borderColor = [[UIUtil colorWithHexString:@"#bdbaba"] CGColor];
    [UIUtil configTextField:_priceProportion withTitle:@""];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (IBAction)submitButton:(id)sender {
     NSDictionary *dic = @{@"userName":[UserModel sharedInstance].userName, @"token":[UserModel sharedInstance].userToken, @"productId":_productId==nil?@"":_productId,@"type":@"1",@"percentage":_priceProportion.text,@"describe":_message.text};
    [RequestData productApply:[UIUtil toJsonString:dic] withBlock:^(NSString *msg, NSError *error) {
        if (error) {
            if ([msg isEqualToString:@"9001"] || [msg isEqualToString:@"9002"]) {
                [UIUtil tokenOverdue:self msg:msg];
            } else {
                [[ESHUDView sharedInstance] showErrorMessage:msg==nil?@"上架失败":msg dismissBlock:nil];
            }
        } else {
            [[ESHUDView sharedInstance] showSuccessMessage:msg dismissBlock:nil];
        }
    }];
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UITextViewDelegate
- (void) textViewDidChange:(UITextView *)textView{
    if ([textView.text length] == 0) {
        [_label setHidden:NO];
    }else{
        [_label setHidden:YES];
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

@end
